package com.lizard.schedule.ui.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.KeyEvent;

import com.lizard.schedule.manager.AccountManager;
import com.lizard.schedule.R;
import com.lizard.schedule.manager.umeng.UmengManager;
import com.lizard.schedule.ui.activity.base.BaseActivity;
import com.lizard.schedule.utils.StatusBarUtil;

/**
 * 闪屏页
 */
public class SplashActivity extends BaseActivity {

    /**
     * 闪屏时间
     */
    private final int SPLASH_TIME = 1500;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.a_splash);

        // 设置状态栏颜色
        StatusBarUtil.setStatusBarColor(this, R.color.schedule_blue);

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                if(AccountManager.getInstance().getLoginType() == AccountManager.LOGIN_TYPE_NO_RECORD){
                    // 跳转到登录页
                    startActivity(new Intent(SplashActivity.this, LoginActivity.class));
                } else{
                    // 免登录跳转到主页
                    Intent intent = new Intent(SplashActivity.this, MainPageActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putBoolean(MainPageActivity.PARAM_VERIFY_ACCOUNT, true); // 注册用户免登录需要进去以后后台验证
                    intent.putExtras(bundle);
                    startActivity(intent);
                }
                finish();
            }
        }, SPLASH_TIME);

    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {

        switch(keyCode){
            case KeyEvent.KEYCODE_BACK: // 设备返回键
                return true;
        }

        return super.onKeyDown(keyCode, event);
    }

}
